import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:power_house/util/common_toast.dart';
import 'package:power_house/widgets/commom_radio_form_item.dart';
import 'package:power_house/widgets/common_floating_button.dart';
import 'package:power_house/widgets/common_form_item.dart';
import 'package:power_house/widgets/common_image_picker.dart';
import 'package:power_house/widgets/common_title.dart';
import 'package:power_house/widgets/room_appliance.dart';
import '../../widgets/common_select_form_item.dart';

class RoomAddPage extends StatefulWidget {
  const RoomAddPage({Key? key}) : super(key: key);

  @override
  State<RoomAddPage> createState() => _RoomAddPageState();
}

class _RoomAddPageState extends State<RoomAddPage> {
  int rentType = 0; //租房类型状态
  int decorationType = 0; //装修类型状态

  int roomType = 0; //房屋类型
  int floor = 0; //楼层
  int oriented = 0; //房屋朝向

  var titleController = TextEditingController();
  var descController = TextEditingController();

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('房屋提交'),
        centerTitle: true,
      ),
      body: ListView(
        children: [
          const CommonTitle('房源信息'),
          CommonFormItem(
              label: '小区',
              contentBuilder: (context) {
                return GestureDetector(
                  onTap: () => {Navigator.of(context).pushNamed('selectRegion')},
                  behavior: HitTestBehavior.translucent, //空白处也响应事件
                  child: SizedBox(
                    height: 40.0,
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: const [
                        Text(
                          '请选择小区',
                          style: TextStyle(fontSize: 16.0),
                        ),
                        Icon(Icons.keyboard_arrow_right)
                      ],
                    ),
                  ),
                );
              },
              hintText: '请输入租金',
              controller: TextEditingController()),
          CommonFormItem(label: '租金', suffixText: '元/月', hintText: '请输入租金', controller: TextEditingController()),
          CommonFormItem(label: '大小', suffixText: '平方米', hintText: '请输入房屋面积', controller: TextEditingController()),
          CommonRadioFormItem(
              label: '租赁方式',
              options: const ['合租', '整租'],
              value: rentType,
              onChange: (index) {
                setState(() {
                  rentType = index;
                });
              }),
          CommonSelectFormItem(
            label: '户型',
            value: roomType,
            onChange: (val) {
              setState(() {
                roomType = val;
              });
            },
            options: const ['一室', '二室', '三室', '四室'],
          ),
          CommonSelectFormItem(
            label: '楼层',
            value: floor,
            onChange: (val) {
              setState(() {
                floor = val;
              });
            },
            options: const ['高楼层', '中楼层', '低楼层'],
          ),
          CommonSelectFormItem(
            label: '朝向',
            value: oriented,
            onChange: (val) {
              setState(() {
                oriented = val;
              });
            },
            options: const ['东', '南', '西', '北'],
          ),
          CommonRadioFormItem(
              label: '装修',
              options: const ['精装', '简装'],
              value: decorationType,
              onChange: (index) {
                setState(() {
                  decorationType = index;
                });
              }),
          const CommonTitle('房屋图片'),
          CommonImagePicker(
            onChange: (List<XFile> files) {},
          ),
          const CommonTitle('房源标题'),
          Container(
            padding: const EdgeInsets.only(left: 10.0, right: 10.0),
            child: TextField(
              controller: titleController,
              decoration: const InputDecoration(
                border: InputBorder.none,
                hintText: '请输入标题（例如：整租，小区名，2室，2000元）',
              ),
            ),
          ),
          const CommonTitle('房源配置'),
          RoomAppliance(onChange: (data){}),
          const CommonTitle('房源描述'),
          Container(
            padding: const EdgeInsets.only(left: 10.0, right: 10.0),
            margin: const EdgeInsets.only(bottom: 100.0),
            child: TextField(
              maxLines: 10,
              controller: descController,
              decoration: const InputDecoration(
                border: InputBorder.none,
                hintText: '请输入房屋描述信息',
              ),
            ),
          )
        ],
      ),
      floatingActionButton: CommFloatingActionButton(
        '提交',
        () => {CommonToast.showToast('点击了提交按钮')},
      ),
      floatingActionButtonLocation: FloatingActionButtonLocation.centerFloat,
    );
  }
}
